#pragma once


#include "flycapture2defs.h"
#include "flycapture2.h"
#include "FrameRateCounter.h"
#include "SMEyeParams.h"

#include "cv.h"
#include "SMEye.h"


class CPTCamera
{
public:
	CPTCamera(void);
	~CPTCamera(void);

	void setParams(CSMEyeParams* pParam);
	bool start(FlyCapture2::PGRGuid guid, HWND hWndView);
	void stop();
	void pause(bool bPause);
	double GetFrameRate();
	ED_EyeInfo* getEyeInfoRaw() {return &m_eyeInfoRaw;};
	ED_EyeInfo* getEyeInfoCalibrated(){ return &m_eyeInfoCalibrated;};

	// The object grab image loop.  Only executed from within the grab thread.
    UINT DoGrabLoop();
	
protected:
	HWND m_hWndView;
	FlyCapture2::PGRGuid m_guid;
	FlyCapture2::Camera m_camera;  
	FlyCapture2::CameraInfo m_cameraInfo;

	// Critical section to protect access to the raw image
    CCriticalSection m_csRawImageData;
	IplImage* m_pImgRaw;
	IplImage* m_pImgProcessed;

	// Critical section to protect access to the processed image
    CCriticalSection m_csProcessing;


	bool m_bContinueGrabThread;
	CWinThread* m_grabLoopThread;
    HANDLE m_threadDoneEvent;

	
	//framerate counter
	CFrameRateCounter m_FrameRate;

	//parameters
	CSMEyeParams* m_pParam;

	//eye info
	ED_EyeInfo m_eyeInfoRaw, m_eyeInfoCalibrated;
	bool m_bResetTorsion;

	// The image grab thread.
    static UINT ThreadGrabImage( void* pparam );
	bool setCameraParameters();
	void processImage();
	void calibrate();
	
	
};

